package jst.householdmanager;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class GlobalFunc {

	public static boolean Like(String str, String expr) {
		expr = expr.toLowerCase();
		expr = expr.replace(".", "\\.");
		expr = expr.replace("?", ".");
		expr = expr.replace("%", ".*");
		str = str.toLowerCase();
		return str.matches(expr);
	}

	public static String DateToString(Date date) {
		if (date == null) {
			return "0000-00-00";
		} else {
			return new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(date);
		}
	}

	public static Date StringToDate(String date) {
		try {
			if (date.matches("0000-00-00")) {
				return null;
			} else {
				return new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).parse(date);
			}
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}
}
